package cn.edu.jxau.test;

import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

public class Main {

	public static void main(String[] args) throws IOException {
		System.out.println(checkReverseEqual("waterbottle", "erbottlewat"));
	}

	public static boolean checkReverseEqual(String s1, String s2) {

		Objects.requireNonNull(s1, "参数s1不能为null");
		Objects.requireNonNull(s2, "参数s2不能为null");
		if (s1.length() == s2.length()) {
			return isSubstring(s1 + s1, s2);
		}
		return false;
	}

	private static boolean isSubstring(String s1, String s2) {

		int len1 = s1.length();
		int len2 = s2.length();
		for (int i = 0; i < len1; i++) {
			int temp = i;
			int j = 0;
			while (i < len1 && j < len2 && s1.charAt(i) == s2.charAt(j)) {
				j++;
				i++;
			}
			if (j >= s2.length()) {
				return true;
			}
			i = temp;
		}
		return false;
	}

}